home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / OOP.SWG / 0057_TV Password Unit.pas < prev    next >
Pascal/Delphi Source File  |  1995-02-28  |  5KB  |  182 lines

  1. Unit Passwd;
  2. {***************************************************************************
  3. Written by Mark S. Van Leeuwen.
  4. This Code is Public Domain.
  5. Please Include my Name in any application that uses this code.
  6. ***************************************************************************}
  7.  
  8. Interface
  9.  
  10. Uses Objects,Dialogs,Views,Drivers;
  11.  
  12. Type
  13. PPasswordLine=^TPasswordLine;
  14. TPasswordLine=Object(TInputline)
  15. Data1  :String;
  16. Constructor Init(Var Bounds :TRect; AMaxLen :Integer);
  17. Procedure GetData(Var Rec);Virtual;
  18. Procedure SetData(Var Rec);Virtual;
  19. Procedure HandleEvent(Var Event :TEvent);Virtual;
  20. End;
  21.  
  22. Implementation
  23.  
  24. {**************** Constructor for the Password Inputline Data **************}
  25. Constructor TPasswordLine.Init(Var Bounds :TRect; AMaxlen :Integer);
  26. Begin
  27. Data1:='';
  28. TInputline.Init(Bounds,AMaxLen);
  29. End;
  30. {******************* Get Data from Procedure *******************************}
  31. Procedure TPasswordLine.GetData(Var Rec);
  32. Begin
  33. String(Rec):=Data1;
  34. End;
  35. {****************** Set Data to Procedure **********************************}
  36. Procedure TPasswordLine.SetData(Var Rec);
  37. Begin
  38. Data1:=String(Rec);
  39. SelectAll(True);
  40. End;
  41. {******************** Handle Inputline Event *******************************}
  42. Procedure TPasswordLine.HandleEvent(Var Event :TEvent);
  43. Var
  44. C :String[1];
  45. Begin
  46.   With Event Do
  47.     If (What = evKeyDown) And (KeyCode = kbEsc) Then
  48.     Begin
  49.       What := Command;
  50.       Command := cmClose;
  51.     End;
  52.    Case Event.What Of
  53.     evKeyDown:
  54.       Begin
  55.          If(UpCase(Event.CharCode) In ['A'..'Z','0'..'9']) Then
  56.            Begin
  57.          C:=Event.CharCode;
  58.          Data1:=Concat(Data1,C);
  59.          Event.CharCode:='*';
  60.          End;
  61.         If(Event.KeyCode = kbBack) OR (Event.KeyCode = kbDel) Then
  62.           Begin
  63.           If(Integer(Data1[0]) <> 0)Then
  64.             Begin
  65.             Dec(Data1[0]);
  66.             End;
  67.           Event.KeyCode:=kbBack;
  68.         End;
  69.       End;
  70.     evBroadcast:
  71.       Begin
  72.       End;
  73.   End;
  74. TInputLine.HandleEvent(Event);
  75. End;
  76. End.
  77.  
  78. { -----------------   DEMO ---------------- }
  79.  
  80. Program TestPwd;
  81.  
  82. {***************************************************************************
  83. Written by Mark S. Van Leeuwen.
  84. This Code is Public Domain.
  85. This is a Test Program that shows the use of the unit.
  86. Please Include my Name in any application that uses this code.
  87. ***************************************************************************}
  88.  
  89. Uses Objects,App,Dialogs,Drivers,Passwd,Views,StdDlg,MsgBox,Menus;
  90.  
  91. Const
  92. cmPassword = 1001;
  93.  
  94. Type
  95. PTestApp=^TTestApp;
  96. TTestApp=Object(TApplication)
  97. Procedure HandleEvent(Var Event:TEvent);Virtual;
  98. Procedure InitStatusLine;Virtual;
  99.  
  100. End;
  101.  
  102. Procedure TTestApp.HandleEvent(Var Event:TEvent);
  103. Procedure Password;
  104. Var
  105.  D         : PDialog;
  106.  Control   : Word;
  107.  A         : PView;
  108.  R         : TRect;
  109.  S         : String;
  110.  Begin
  111.   R.Assign(0,0,30,08);
  112.   D := New(PDialog, Init(R, 'Enter Password'));
  113.   With D^ Do
  114.   Begin
  115.   Options := Options or ofCentered;
  116.  
  117.     R.Assign(02, 05, 12, 07);
  118.     Insert(New(PButton, Init(R, 'O~K', cmOk, bfDefault)));
  119.  
  120.     R.Assign(15, 05, 25, 07);
  121.     Insert(New(PButton, Init(R, '~C~ancel', cmCancel, bfNormal)));
  122.  
  123.     R.Assign(02,03,28,04);
  124.     Insert(New(PStaticText, Init(R,'Password is not Displayed.')));
  125.  
  126.     R.Assign(02,02,28,03);
  127.     A:= New(PPasswordLine, Init(R,10));
  128.     Insert(A);
  129.     R.Assign(02,01,28,02);
  130.     Insert(New(Plabel, Init(R,'Enter Password:',A)));
  131.  
  132.    End;
  133.     Control:=Desktop^.ExecView(D);
  134.     IF Control <> cmCancel THEN
  135.       Begin
  136.       A^.GetData(S);
  137.       MessageBox(S,nil,mfInformation+mfOkButton);
  138.     End;
  139.     Dispose(D, Done);
  140.  End;
  141.  
  142. Begin
  143.  TApplication.HandleEvent(Event);
  144.   case Event.What of
  145.     evCommand:
  146.       begin
  147.         case Event.Command of
  148.          cmPassword             : Password;
  149.          else
  150.           Exit;
  151.         end;
  152.         ClearEvent(Event);
  153.       end;
  154.   end;
  155. end;
  156. {***************************************************************************}
  157. {**************** Application Status Line Procedure ************************}
  158. {***************************************************************************}
  159.  Procedure TTestApp.InitStatusLine;
  160.  Var
  161.  R :Trect;
  162.  Begin
  163.   GetExtent(R);
  164.   R.A.Y := R.B.Y - 1;
  165.   StatusLine := New(PStatusLine, Init(R,
  166.     NewStatusDef(0, $FFFF,
  167.       NewStatusKey('~F1~ Help', kbF1, cmHelp,
  168.       NewStatusKey('~F2~ Password', kbF2, cmPassword,
  169.       NewStatusKey('~F10~ Menu', kbF10, cmMenu,
  170.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,nil)))), nil)));
  171. End;
  172.  
  173.  
  174. Var
  175. TMyApp  :TTestApp;
  176.  
  177. Begin
  178. TMyapp.Init;
  179. TMyapp.Run;
  180. TMyapp.Done;
  181. End.
  182.